import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:ct_pa_majordomo/widgets/button/tap_container.dart";
import "package:ct_pa_majordomo/widgets/divider/solid_divider.dart";
import "package:flutter/material.dart";

class BottomSheetMenuItem {
  final String text;
  final void Function()? onTap;

  BottomSheetMenuItem(this.text, {this.onTap,});
}

class BottomSheetMenu extends StatelessWidget {
  final List<BottomSheetMenuItem> items;
  final void Function()? onCancel;

  const BottomSheetMenu({super.key, required this.items, this.onCancel});

  @override
  Widget build(BuildContext context) {
    List<BottomSheetMenuItem> list = items..add(BottomSheetMenuItem("取消", onTap: onCancel));
    return ListView.separated(
      itemCount: list.length,
      shrinkWrap: true,
      itemBuilder: (context, index) {
        BottomSheetMenuItem item = list[index];
        return TapContainer(
          height: 56,
          textStyle: const TextStyle(fontSize: 16),
          onTap: () {
            Stacker.pop();
            if (item.onTap != null) item.onTap!();
          },
          child: Text(item.text),
        );
      },
      separatorBuilder: (context, index) => const SolidDivider(),
    );
  }
}
